package org.example.com.RabbitMq.Controller;

import lombok.extern.slf4j.Slf4j;
import org.example.com.RabbitMq.config.DirectConfig;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
public class DirectController {

    @Resource
    private AmqpTemplate amqpTemplate;

    @GetMapping("/direct/send")
    public String send(String msg){
        log.info("send :{}" , msg);
        amqpTemplate.convertAndSend(DirectConfig.exName,null,msg);
        return "ok";
    }

    //@RabbitListener(queues = DirectConfig.queueName)
    public void processA(String msg) {
        log.info("Receiver A:{}", msg);
    }

    //@RabbitListener(queues = DirectConfig.queueName)
    public void processB(String msg) {
        log.info("Receiver B:{}", msg);
    }

}
